Skip to content

Document pydantic support for Structs, Enums and NumPy arrays - #791

Closed
Lotion-3 wants to merge 1 commit into
Point72:mainfrom
Lotion-3:docs/pydantic-integration
Closed

Lotion-3 wants to merge 1 commit into
Point72:mainfrom
Lotion-3:docs/pydantic-integration

Conversation

@Lotion-3

Copy link
Copy Markdown

Fixes #431.

Adds a "Pydantic integration" section to the csp.Struct API page, covering the behaviour from #428:

  • validating and serializing structs with type_adapter() or inside a BaseModel;
  • how underscore fields and field types without a pydantic schema are handled (they're passed to the struct without pydantic validation);
  • how serializing with pydantic differs from to_dict / to_json (enums, Annotated serializers, datetime and timedelta formats);
  • csp.Enum validation and JSON schema;
  • the csp.typing.Numpy1DArray / NumpyNDArray annotations.

It also adds type_adapter() to the list of struct methods and the use_pydantic argument to from_dict.

The outputs shown in the examples were produced with csp 0.19.1 and pydantic 2.14, and make lint-docs passes.

Add a "Pydantic integration" section to the csp.Struct API page that
describes the behaviour added in Point72#428: validating and serializing
Structs with pydantic, how underscore fields and types without a
pydantic schema are handled, how pydantic serialization differs from
to_dict/to_json, csp.Enum validation, and the csp.typing NumPy array
annotations. Also document type_adapter() and the use_pydantic
argument of from_dict.

Fixes Point72#431

Signed-off-by: Laksh Agarwal <lakshagarwal65@gmail.com>
@timkpaine

Copy link
Copy Markdown
Member

Thanks for the PR! I've consolidated some docs updates in #795

@timkpaine timkpaine closed this Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detail pydantic integration with csp on docs

2 participants